package ca.qc.bdeb.info.pp2.tp2.controleur;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class CommandeComparerProprietes implements Commande
{
    private String next;

    public CommandeComparerProprietes(String next)
    {
        this.next = next.toLowerCase();
    }

    @Override
    public String executer(HttpServletRequest req) throws CommandeException
    {
        String param;
        List<String> ids = new ArrayList<String>();

        /* Récupère toutes les propriétés */
        for (String p : req.getParameterMap().keySet())
            if (p.startsWith(ConstantesWeb.ATTRIBUT_COMPARER_ID)) {
                param = req.getParameter(p);

                if (param.equals(ConstantesWeb.SELECTION_CHECKBOX_ON))
                    ids.add(p.substring(ConstantesWeb.ATTRIBUT_COMPARER_ID.length()));
            }

        req.setAttribute(ConstantesWeb.VALEURS_LISTE_IDS_PROPRIETES, ids);

        return next;
    }
}
